package com.edgardleal.pixelruler;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

public class RulerPanel extends JPanel {
	private int lineGuidePosition = 0;

	private static final long serialVersionUID = 5886461811407255448L;
	public RulerPanel() {
		super(true);
	}

	private void paintGuideLine(Graphics g) {
		g.setColor(Color.blue);
		g.drawLine(getLineGuidePosition(), 0, getLineGuidePosition(), 50);
	}

	public int getLineGuidePosition() {
		return lineGuidePosition;
	}

	public void setLineGuidePosition(int lineGuidePosition) {
		this.lineGuidePosition = lineGuidePosition;
		this.repaint();
	}

	private void paintValue(Graphics g) {
		g.setColor(Color.black);
		g.drawString(String.format("Largura: %d", getLineGuidePosition()), 5,
				this.getHeight() - 15);
	}

	@Override
	public void paint(Graphics g) {
		// super.paint(g);
		g.drawRect(0, 0, this.getWidth(), this.getHeight());
		g.setColor(Color.white);
		g.fillRect(1, 1, this.getWidth() - 3, this.getHeight() - 3);
		g.setColor(Color.black);
		for (int i = 0; i < 500; i++) {
			if (i % 2 == 0)
				g.drawLine(i, 0, i, i % 10 == 0 ? 20 : 10);
		}
		paintGuideLine(g);
		paintValue(g);
	}

}
